package com.tengju.settlement.infrastructure.repository;

import com.tengju.data.domain.model.report.AchievementBonusRepository;
import com.tengju.data.domain.shared.DateUtil;
import com.tengju.settlement.domain.model.AchievementRepository;
import com.tengju.settlement.domain.model.AchievementStatus;
import com.tengju.settlement.domain.model.account.UserIdCode;
import com.tengju.settlement.domain.shared.Amount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

@Repository
public class AchievementRepositoryImpl implements AchievementRepository {

    @Autowired
    AchievementBonusRepository externalBonusRepository;

    @Override
    public Amount sum(UserIdCode idCode, AchievementStatus status) {
        BigDecimal bonus = externalBonusRepository.getBonus(idCode.getValue(), status.getVal(), null);
        return new Amount(bonus);
    }


    @Override
    public Amount sum(UserIdCode idCode, AchievementStatus status, LocalDate month) {
        Integer monthInt = DateUtil.formatMonthInt(month.atTime(0,0));
        BigDecimal bonus = externalBonusRepository.getBonus(idCode.getValue(), status.getVal(), monthInt);
        return new Amount(bonus);
    }
}
